package utils;

import android.text.TextUtils;
import android.util.Log;

import base.BaseApplication;

/**
 * Created by Administrator on 2018/10/11.
 */

public class API {
    /**
     * 01.心跳
     */
    public static String xintiao() {
        String mi0 = (String) SpfUtils.get(BaseApplication.getInstance(), "mima", "010203040506");
        //心跳
        String ss = "55AA0107"+ mi0+"00";
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }



    /**
     * 02.查询产品信息
     * @param mima
     * @return
     */
    public static String chanpin(String mima) {

        String ACC;
        String ss = null;
        //未绑定 传"",绑定需要传密码
        if (TextUtils.isEmpty(mima)) {
            mima ="55AA0206" + "010203040506";
            ACC = "1C";
            ss =mima+ACC;
        } else {
            ss = "55AA0206" + mima  ;
            String jiegguo = WW.makeChecksum(ss) ;
            String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
            ss=ss+substring;
        }

        return  ss;
    }


    /**
     * 03.设置时间
     * @param shijian
     * @return
     */
    public  static  String shezhishijian(String shijian) {
//        01 02 03 04 05 06 12 0A 0A 03 09 00 00


        String ss = "55AA030D"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return ss;
    }


    /**
     * 04.预约下发
     * @param shijian
     * @return
     */
    public static String yuyuexiafa(String shijian) {
//          01 02 03 04 05 06 01 01 01 02 02 02 03 03 03 04 04 04 05 05 05 06 06 06 07 07 07
//        01 02 03 04 05 06 09 00 03 00 00 00 0C 00 06 00 00 00 0C 00 03 00 00 00 00 00 00

        String ss = "55AA041B"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 05.设置工作模式
     * @param shijian
     * @return
     */
    public static String gongzuomoshi(String shijian) {

//        01 02 03 04 05 06 02

        String ss = "55AA0507"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 06.设置分区域割草时间
     * @param shijian
     * @return
     */
    public static String quyuegecao(String shijian) {

//        01 02 03 04 05 06 02

        String ss = "55AA0607"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 07.APP和割草机绑定
     * @param shijian
     * @return
     */
    public static String bangding(String shijian) {

//        01 02 03 04 05 06 08 08 08 08 08 08

        String ss = "55AA070C"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }
    /**
     * 08.服务器解绑设备
     * @param shijian
     * @return
     */
    public  static String huoqupincode(String shijian) {

//        01 02 03 04 05 06 08 08 08 08 08 08

        String ss = "55AA0806"+ shijian   ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        Log.e("0806", "xx"+ss);
        return  ss;
    }

    /**
     * 09.设置开机是否需要APP确认
     * @param shijian
     * @return
     */
    public static String kaijiequeren(String shijian) {

//        01 02 03 04 05 06 01

        String ss = "55AA0907"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 10.
     割草机开机APP确认下发
     * @param shijian
     * @return
     */
    public  static  String kaijiquerenxiafa(String shijian) {

//        01 02 03 04 05 06 01

        String ss = "55AA0A07"+ shijian ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 11.

     预约失败上报
     * @param shijian
     * @return
     */
    public static String yuyueshibaishangbao(String shijian) {

//        01 02 03 04 05 06 01

        String ss = "55AA0B07"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }




    /**
     *

     1.13.设置围栏线长度
     * @param shijian
     * @return
     */
    public static String oc(String shijian) {

//        01 02 03 04 05 06 01

        String ss = "55AA0C08"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

    /**
     * 字符串转化成为16进制字符串
     * @param s
     * @return
     */
    public static String strTo16(String s) {
        String str = "";
        for (int i = 0; i < s.length(); i++) {
            int ch = (int) s.charAt(i);
            String s4 = Integer.toHexString(ch);
            str = str + s4;
        }
        return str;
    }

    /**
     * 05.密码回复
     * @param shijian
     * @return
     */
    public static String maimahuifu(String shijian) {

//        01 02 03 04 05 06 02

        String ss = "55AA0D07"+ shijian  ;
        String jiegguo = WW.makeChecksum(ss);
        String substring = jiegguo.substring(jiegguo.length() - 2, jiegguo.length());
        ss=ss+substring;
        return  ss;
    }

}
